<%@page import="com.log.*"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" name="author" content="20201212杨铖宇">
<title>Log</title>
<!-- 引入css、js -->
<link rel="stylesheet" href="css/log.css">
<link rel="stylesheet" href="https://www.jq22.com/jquery/bootstrap-4.2.1.css">
<script src="js/login.js"></script>
<script src="js/jquery.js"></script>
<script src="js/lin_search.js"></script>
<script src="js/bootstrap.js"></script>
<style>
  #lin {
    margin: 20px 0;
    height: 30px;
    padding: 5px;
    box-sizing: border-box;
  }
  .names {
    width: 120px;
    margin-bottom: 0px;
    input:disabled + label {/*禁用的指针*/
	cursor: not-allowed
	}
.RadioStyle input {
	display: none
	}
.RadioStyle label {
	border: 1px solid #CCC;
	color: #666;
	padding: 2px 10px 2px 5px;
	line-height: 28px;
	min-width: 80px;
	text-align: center;
	float: left;
	margin: 2px;
	border-radius: 4px
	}
.RadioStyle input:checked + label {
	background: url('img/ico_checkon.svg') no-repeat right bottom;
	border: 1px solid #00a4ff;
	background-size: 21px 21px;
	color: #00a4ff
	}
</style>
</head>
<body>
	<!--背景变换-->
	<div class="slideshow">
		<div class="slideshow-image"
			style="background-image: url('img/wallhaven1.png')"></div>
		<div class="slideshow-image"
			style="background-image: url('img/wallhaven3.png')"></div>
		<div class="slideshow-image"
			style="background-image: url('img/wallhaven4.png')"></div>
		<div class="slideshow-image"
			style="background-image: url('img/wallhaven5.png')"></div>
	</div>
	<!--导航栏-->
	<ul>
		<li><a class="active" href="https://ycy20201212.github.io/">Home</a></li>
		<li><a href="https://www.sohu.com/">News</a></li>
		<li><a href="https://www.cnblogs.com/20201212ycy/">Contact</a></li>
		<li><a href="Jacap.jsp">流量审计</a></li>
		<li><a href="Usb.jsp">USB审计</a></li>
		<li style="float: right"><a href="About.html">About</a></li>
	</ul>
	<!--主体-->
	<div class="container switch">
		<%
	      	//此地方写java代码
	      	//获取错误信息
	      	String errorinfo=null;
	      	errorinfo=request.getParameter("error");
	      	if("1".equals(errorinfo)){%>
			<script type="text/javascript" language="javascript">
			alert("不能全为空");			// 弹出错误信息
			window.location='Log.jsp';	// 跳转到登录界面
			</script>
			<%}%>
		<form  method="post" action="Logcheck" class="form" align="center">
			<table id="pageListTable">
				<thead class="fixed_header">
					<tr>
						<th>
							<select class="form-control names" id="select">
							  <option>Log Name</option>
						      <option>System</option>
						      <option>Application</option>
							  <option>Security</option>
						      <option>Setup</option>
						      <option>ForwardedEvents</option>
						    </select>
						</th>
						<th>Source</th>
						<th>Date</th>
						<th><input type="text" id="lin" placeholder="Event ID"></th>
						<th>Task</th>
						<th>
							<select class="form-control names" id="select">
							  <option>Level</option>
						      <option>信息</option>
						      <option>警告</option>
							  <option>错误</option>
						      <option>关键</option>
						      <option>关闭</option>
						    </select>
						</th>
						<th>Opcode</th>
						<th>Keyword</th>
						<th>User</th>
						<th>User Name</th>
						<th>Computer</th>
					</tr>
				</thead>
				<tbody id="pageListTableBody">
					<%
					ArrayList<Logs> list = (ArrayList<Logs>) request.getAttribute("loglist");
					if (list == null || list.toString().equals("[]")) {%>
		      		<h2>暂无日志数据</h2>
		      		<%}
					else {
						for (Logs l : list) {
					%>
					<tr>
						<td><%=l.getLogName()%></td>
						<td><%=l.getSource()%></td>
						<td><%=l.getDate()%></td>
						<td><%=l.getEventID()%></td>
						<td><%=l.getTask()%></td>
						<td><%=l.getLevel()%></td>
						<td><%=l.getOpcode()%></td>
						<td><%=l.getKeyword()%></td>
						<td><%=l.getUser()%></td>
						<td><%=l.getUserName()%></td>
						<td><%=l.getComputer()%></td>
					</tr>
					<%
					}
					}
					%>
				</tbody>
			</table>
			<% if (list == null || list.toString().equals("[]")) {%>
			<div class="RadioStyle">
			    <div class="Block PaddingL">
			        <input id="System" value="System" name='checkType' type="checkbox" checked /><label for="System">系统日志</label>
				    <input id="Application" value="Application" name='checkType' type="checkbox" /><label for="Application">应用程序日志</label>
				    <input id="Security" value="Security" name='checkType' type="checkbox" /><label for="Security">安全日志</label>
				    <input id="Setup" value="Setup" name='checkType' type="checkbox" /><label for="Setup">Setup日志</label>
				    <input id="ForwardedEvents" name='checkType' value="ForwardedEvents" type="checkbox" /><label for="ForwardedEvents">Forwarded Events日志</label>
			    </div>	
			</div>
			<br>
					<p><h4><input type="submit" value="开始审计" ></h4></p>
			<%}else{
					int pagenum = Integer.parseInt(request.getParameter("pagenum"));	// 页数%>
				<p><a href="Loglist?pagenum=<%=pagenum-1%>">数据库分页上一页</a>&emsp;第 <strong><%=pagenum%></strong> 页&emsp;<a href="Loglist?pagenum=<%=pagenum+1%>">数据库分页下一页</a></p>
				<div id="pageBox">
					&emsp;&emsp; <span id="spanFirst">首页</span> <span id="spanPre">上一页</span>
					<span id="spanNext">下一页</span> <span id="spanLast">尾页</span> <br>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
					第 <strong id="spanPageNum"></strong> 页/共 <strong id="spanTotalPage"></strong>
					页
				</div>
			<%} %>
	</div>
	</form>
	</div>

	<script>
	    //  表1
	    $("#lin").on('keyup', function () {
	      var table1 = $("#pageListTable");
	      var input = $(this);
	      new Search(table1, input,)
	    })
		// 表2
	    $('#select').on('change', function () {
	      var content = $('#select') // 下拉框
	      var table2 = $('#pageListTable')
	      new Search(table2, content, '#6332f6')
	    })
		var theUL = document.getElementById("pageListTableBody");
		var totalPage = document.getElementById("spanTotalPage");
		var pageNum = document.getElementById("spanPageNum"); //获取当前页<span>
		var spanPre = document.getElementById("spanPre"); //获取上一页<span>
		var spanNext = document.getElementById("spanNext"); //获取下一页<span>
		var spanFirst = document.getElementById("spanFirst"); //获取第一页<span>
		var spanLast = document.getElementById("spanLast"); //获取最后一页<span>
		var numberRowsInTable = theUL.getElementsByTagName("tr").length; //记录总条数
		var pageSize = 4; //每页显示的记录条数
		var page = 1; //当前页，默认第一页

		//下一页
		function next() {
			hideTable();
			currentRow = pageSize * page;
			maxRow = currentRow + pageSize;
			if (maxRow > numberRowsInTable)
				maxRow = numberRowsInTable;
			for (var i = currentRow; i < maxRow; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = '';
			}
			page++;
			if (maxRow == numberRowsInTable) {
				nextText();
				lastText();
			}
			showPage();
			preLink();
			firstLink();
		}

		//上一页
		function pre() {
			hideTable();
			page--;
			currentRow = pageSize * page;
			maxRow = currentRow - pageSize;
			if (currentRow > numberRowsInTable)
				currentRow = numberRowsInTable;
			for (var i = maxRow; i < currentRow; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = '';
			}
			if (maxRow == 0) {
				preText();
				firstText();
			}
			showPage();
			nextLink();
			lastLink();
		}

		//第一页
		function first() {
			hideTable();
			page = 1;
			for (var i = 0; i < pageSize; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = '';
			}
			showPage();
			firstText();
			preText();
			nextLink();
			lastLink();
		}

		//最后一页
		function last() {
			hideTable();
			page = pageCount();
			currentRow = pageSize * (page - 1);
			for (var i = currentRow; i < numberRowsInTable; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = '';
			}
			showPage();
			preLink();
			nextText();
			firstLink();
			lastText();
		}

		function hideTable() {
			for (var i = 0; i < numberRowsInTable; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = 'none';
			}
		}

		function showPage() {
			pageNum.innerHTML = page;
		}

		//总共页数
		function pageCount() {
			return Math.ceil(numberRowsInTable / pageSize);
		}
		//显示链接
		function preLink() {
			spanPre.innerHTML = "<a href='javascript:pre();'>上一页</a>";
		}
		function preText() {
			spanPre.innerHTML = "上一页";
		}
		function nextLink() {
			spanNext.innerHTML = "<a href='javascript:next();'>下一页</a>";
		}
		function nextText() {
			spanNext.innerHTML = "下一页";
		}
		function firstLink() {
			spanFirst.innerHTML = "<a href='javascript:first();'>首页</a>";
		}
		function firstText() {
			spanFirst.innerHTML = "首页";
		}
		function lastLink() {
			spanLast.innerHTML = "<a href='javascript:last();'>末页</a>";
		}
		function lastText() {
			spanLast.innerHTML = "末页";
		}

		//隐藏
		function hide() {
			for (var i = pageSize; i < numberRowsInTable; i++) {
				theUL.getElementsByTagName("tr")[i].style.display = 'none';
			}
			totalPage.innerHTML = pageCount();
			pageNum.innerHTML = '1';
			nextLink();
			lastLink();
		}
		hide();
	</script>

</body>
</html>